<<<<<<< HEAD
//表单验证 + 重名检测 + 发送数据给后端(无需js)
!(function reg() {
  const registry = $(".registry"); //form表单
  const tel = $(".tel"); //手机号
  const checkspans = $(".checkspan"); //报错span元素
  const password = $(".password");
  const repass = $(".repass");
  const pwbaron = $(".pw-bar-on");
  // let userflag = true;
=======
//表单验证 + 重名检测 + 发送数据给后端
!(function reg() {
  const registry = $(".registry");
  const tel = $(".tel"); 
  const checkspans = $(".checkspan"); 
  const password = $(".password");
  const repass = $(".repass");
  const pwbaron = $(".pw-bar-on");
  
>>>>>>> dongfang
  let telflag = true;
  let passflag = true;
  let repassflag = true;

  //表单验证
  //1.手机号码

  tel.on("blur", function () {
    checkspans
      .eq(0)
      .css({
        display: "inline-block",
      })
      .html("请输入11位手机号码");
  });

  tel.on("blur", function () {
    if ($(this).val() !== "") {
      let reg = /^1[3456789]\d{9}$/;
      if (reg.test($(this).val())) {
        //重名检测
        $.ajax({
<<<<<<< HEAD
            type: 'post',
            url: 'http://localhost/js2112/dongfang/php/reg.php',
            data: {
                tel: $(this).val()
            }
        }).done(function(data) { //data:后端返回匹配的结果
            if (data === 'false') {
                telflag = true;
            } else {
                checkspans.eq(0).css({
                  display: "inline-block",
                }).html('很抱歉，该手机号码已被使用');
                telflag = false;
            }
        });
    } 
      if (reg.test($(this).val())) {
        checkspans.eq(0).css({display: "none"});
=======
          type: "post",
          url: "http://localhost/js2112/dongfang/php/reg.php",
          data: {
            tel: $(this).val(),
          },
        }).done(function (data) {
          //data:后端返回匹配的结果
          if (data === "false") {
            telflag = true;
          } else {
            checkspans
              .eq(0)
              .css({
                display: "inline-block",
              })
              .html("很抱歉，该手机号码已被使用");
            telflag = false;
          }
        });
      }
      if (reg.test($(this).val())) {
        checkspans.eq(0).css({ display: "none" });
>>>>>>> dongfang
        telflag = true;
      } else {
        checkspans
          .eq(0)
          .css({
            display: "inline-block",
          })
          .html("请输入有效手机");
        telflag = false;
      }
    } else {
      checkspans
        .eq(0)
        .css({
          display: "inline-block",
        })
        .html("请输入11位手机号码");
      telflag = false;
    }
  });

  //2.密码
  // oninput:文本框的内容发生改变
  // 判断弱中强
  password.on("blur", function () {
    //强密码为八位及以上并且大小写字母数字特殊字符三项都包括
    let reg1 = /^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\W).*$/g;
    //中密码为八位及以上并且大小写字母、数字、特殊字符三项中有两项，强度是中等
    let reg2 =
      /^(?=.{8,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[a-z])(?=.*\W))|((?=.*[0-9])(?=.*\W))|((?=.*[A-Z])(?=.*\W))).*$/g;
    //弱密码为四位及单一的大小写字母、数字、特殊字符
    let reg3 = /(?=.{4,}).*/g;

    if (reg1.test($(this).val())) {
      pwbaron.css({
        display: "inline-block",
        width: 180,
        height: 14,
        position: "absolute",
        top: 359,
        left: 240,
      });
<<<<<<< HEAD
     
=======
>>>>>>> dongfang
    } else if (reg2.test($(this).val())) {
      pwbaron.css({
        display: "inline-block",
        width: 120,
        height: 14,
        position: "absolute",
        top: 359,
        left: 240,
      });
<<<<<<< HEAD
      checkspans.eq(1).css({display: "none"});
=======
      checkspans.eq(1).css({ display: "none" });
>>>>>>> dongfang
    } else if (reg3.test($(this).val())) {
      pwbaron.css({
        display: "inline-block",
        width: 60,
        height: 14,
        position: "absolute",
        top: 359,
        left: 240,
      });
      checkspans
        .eq(1)
        .css({
          display: "inline-block",
        })
        .html("该密码比较简单，有被盗风险，建议您改为字母+数字的密码");
    }
<<<<<<< HEAD
    
  });
  password.on("blur", function () {
    if ($(this).val() !== "") {
      //密码不为空
      if ($(this).val().length >= 4 && $(this).val().length <= 20) {
        //长度正确
        if (passflag) {
          //标记成立
          // checkspans.eq(1).css();
=======
  });
  password.on("blur", function () {
    if ($(this).val() !== "") {
     
      if ($(this).val().length >= 4 && $(this).val().length <= 20) {
      
        if (passflag) {
        
>>>>>>> dongfang
        }
      } else {
        checkspans
          .eq(1)
          .css({
            display: "inline-block",
          })
          .html("密码长度为4-20个字符");
        passflag = false;
      }
    } else {
      checkspans
        .eq(1)
        .css({
          display: "inline-block",
        })
        .html("请输入密码");
      passflag = false;
    }
  });

  //3.密码重复
  repass.on("focus", function () {
<<<<<<< HEAD
    checkspans
      .eq(2)
      .css({
      })
      .html("请再次输入密码");
=======
    checkspans.eq(2).css({}).html("请再次输入密码");
>>>>>>> dongfang
  });

  repass.on("blur", function () {
    if ($(this).val() !== "") {
      if (password.val() === $(this).val()) {
<<<<<<< HEAD
        checkspans.eq(2).css({display: "none"});
=======
        checkspans.eq(2).css({ display: "none" });
>>>>>>> dongfang
        repassflag = true;
      } else {
        checkspans
          .eq(2)
          .css({
            display: "inline-block",
          })
          .html("密码输入不一致，请重新确认");
        repassflag = false;
      }
    } else {
      checkspans
        .eq(2)
        .css({
          display: "inline-block",
        })
        .html("请输入确认密码");
      repassflag = false;
    }
  });

  //5.阻止form+submit提交
<<<<<<< HEAD
  //onsubmit事件：表单提交,由form触发的
=======
 
>>>>>>> dongfang
  registry.on("submit", function () {
    if (tel.val() === "") {
      checkspans
        .eq(0)
        .css({
          display: "inline-block",
        })
        .html("用户名不能为空");
      telflag = false;
    }
    if (password.val() === "") {
      checkspans
        .eq(1)
        .css({
          display: "inline-block",
        })
        .html("密码不能为空");
      passflag = false;
    }
    if (repass.val() === "") {
      checkspans
        .eq(2)
        .css({
          display: "inline-block",
        })
        .html("密码重复不能为空");
      repassflag = false;
    }

<<<<<<< HEAD
   
=======
>>>>>>> dongfang
    if (!telflag || !passflag || !repassflag) {
      return false;
    }
  });
})();
